﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Tradex.Trading;

namespace Tradex.Market {

    /// <summary>
    /// The MarketInterest class describes the interest of a participant in market information.
    /// </summary>
    public class MarketInterest {

        /// <summary>
        /// Constructor taking all values.
        /// </summary>
        /// <param name="connector"></param>
        /// <param name="market"></param>
        /// <param name="instrument"></param>
        /// <param name="product"></param>
        /// <param name="type"></param>
        /// <param name="data"></param>
        public MarketInterest(
            string connector,
            string market, string instrument, string product, InstrumentType type,
            MarketInterestType data
        ) {
            Connector = connector;
            Market = market;
            Instrument = instrument;
            Product = product;
            InstrumentType = type;
            Data = data;
        }

        /// <summary>
        /// Gets the Connector
        /// </summary>
        public string Connector { get; private set; }

        /// <summary>
        /// Gets the Market
        /// </summary>
        public string Market { get; private set; }

        /// <summary>
        /// Gets the Instrument
        /// </summary>
        public string Instrument { get; private set; }

        /// <summary>
        /// Gets the Product
        /// </summary>
        public string Product { get; private set; }

        /// <summary>
        /// Gets the instrument type
        /// </summary>
        public InstrumentType InstrumentType { get; private set; }

        /// <summary>
        /// Gets the data of interest
        /// </summary>
        public MarketInterestType Data { get; private set; }

        /// <summary>
        /// Converts an MarketInterestType into a MarketUpdateFilter
        /// </summary>
        /// <param name="interestType"></param>
        /// <returns></returns>
        public static MarketUpdateFilters GetMarketUpdateFilter(MarketInterestType interestType) {
            MarketUpdateFilters filter = MarketUpdateFilters.None;
            switch (interestType) {
                case MarketInterestType.None:
                    break;
                case MarketInterestType.Basic:
                    filter =
                        MarketUpdateFilters.Indicators |
                        MarketUpdateFilters.Settlements |
                        MarketUpdateFilters.Mode;
                    break;
                case MarketInterestType.Limited:
                    filter =
                        MarketUpdateFilters.Indicators |
                        MarketUpdateFilters.Settlements |
                        MarketUpdateFilters.Mode |
                        MarketUpdateFilters.Trades |
                        MarketUpdateFilters.TradeVolume;
                    break;
                case MarketInterestType.Channel:
                    filter =
                        MarketUpdateFilters.Indicators |
                        MarketUpdateFilters.Settlements |
                        MarketUpdateFilters.Mode |
                        MarketUpdateFilters.Trades |
                        MarketUpdateFilters.TradeVolume |
                        MarketUpdateFilters.BestQuotes;
                    break;
                case MarketInterestType.Full:
                    filter =
                        MarketUpdateFilters.All;
                    break;
            }
            return filter;
        }

    }
}
